// 测试获取数据
const listData = [
    {title:"头条新闻",name:"小海",amount:200,address:"上海虹桥机场"},
    {title:"天美科技",name:"小梅",amount:1000,address:"南山区天美大厦"},
    {title:"腾讯新闻",name:"小米",amount:800,address:"南山区腾讯大厦"},
    {title:"百度新闻",name:"小克",amount:300,address:"南山区比克大厦"},
    {title:"乐视TVB",name:"小花",amount:500,address:"福田区科技园"},
    {title:"B站Up主",name:"小美",amount:100,address:"民乐万达广场"},
    {title:"可乐鸡翅",name:"小可",amount:400,address:"龙华高铁站"},
    {title:"梅菜扣肉",name:"小林",amount:900,address:"福田区世纪佳缘"},
    {title:"爆炒龙虾",name:"小乐",amount:1200,address:"南山区深大地铁站"},
    {title:"猥琐发育",name:"小龙",amount:700,address:"北京育新地铁站"},
    {title:"下路混子",name:"小明",amount:500,address:"成都科技高新园"},
]
// 随机字符串 id
const randomId = () => {
    let s4 = function() {
        return (65536 * (1 + Math.random()) | 0).toString(16).substring(1);
    }
    return (s4() + s4() + "-" + s4() + "-4" + s4().substring(0, 3) + "-" + s4() + "-" + s4() + s4()).toUpperCase();
}

// 模拟api获取测试数据
export const testApi = function (page, size, data, total=25) {
    uni.showLoading({ title: '加载中...' })
    const start = (page - 1) * size + 1
    const end = page * size
    const leng = end >= total ?  total : end
    return new Promise((resolve,reject)=>{
      let list = [];
      if(start<=total){
        for (let i = start; i <= leng; i++) {
            let item = Object.assign({}, listData[ Math.floor(Math.random() * 10)], data);
            item.id = randomId();
            item.key = i;
            item.time = new Date()
            list.push(item);
        }
      }
      setTimeout(() => {
        uni.hideLoading();
        let data = {
          status: 1,
          data: list,
          msg: '查询成功',
          total
        }
        resolve(data)
      }, 1000);
    })
  }
  